package com.link.base.base.product.service;

import com.link.base.base.mvg.model.Mvg;
import com.link.base.base.product.dao.mybatis.mapper.TagMapper;
import com.link.base.base.product.model.Tag;
import com.link.base.base.mvg.dao.mybatis.product.mapper.ProductTagMvgMapper;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.service.BasicServiceException;
import com.link.core.basic.service.BasicServiceImpl;
import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author unknown
 * @date unknown
 * @comments 标签
 */
@Service
public class TagServiceImpl extends BasicServiceImpl<Tag> implements TagService {

    @Resource
    private TagMapper tagMapper;
    @Resource
    private ProductTagMvgMapper productTagMvgMapper;

    @Override
    public BasicMapper<Tag> getBasicMapper() {
        return tagMapper;
    }

    @Override
    @Transactional(rollbackFor = BasicServiceException.class)
    public void deleteTagAndProdById(Tag tag) throws Exception {
        this.deleteById(tag);
        Mvg mvg = new Mvg();
        mvg.setCorpid(tag.getLoginCorpId());
        mvg.setMvgSubsetId(tag.getId());
        productTagMvgMapper.deleteInterByTagOrProdId(mvg);
    }


    @Override
    public List<Tag> queryProdTags(Tag guideProdTag) throws Exception {
        return tagMapper.queryProdTags(guideProdTag);
    }
}
